package com.me.learnspring.controller;

import lombok.var;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/")
public class RouterController {
	@GetMapping("info")
	public Map<String, Object> info(HttpServletRequest req) {
		var map = new HashMap<String, Object>();
		map.put("客户ip", req.getRemoteAddr());
		map.put("客户访问的页面", req.getHeader("user-agent"));
		map.put("客户访问页面", req.getRequestURI());
		return map;
	}
	
	@GetMapping("freemarker")
	public ModelAndView freemarker() {
		ModelAndView mv = new ModelAndView("first");
		mv.addObject("name", "LFT");
		mv.addObject("price", 2000);
		mv.addObject("date", new Date());
		mv.addObject("gender", true);
		mv.addObject("major", "软件专业");
		return mv;
	}
	
	// @GetMapping
	// public String redirect(){
	// 	return "redirect:/category/";
	// }
	
	// @GetMapping
	// public String forward(){
	// 	return "forward:/category";
	// }
	
	// @GetMapping
	// public String routeToCategoryW(){
	// 	return "/category";
	// }
}
